/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.bl;

import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import program.beans.Bill;
import program.beans.Category;
import program.database.Database;

/**
 * Controller-class for bills, which are stored in the database. Implemented in
 * singleton
 *
 * Responsible: Bernhard
 */
public class PrintBillController {

    private ArrayList<Category> categories = new ArrayList<>();
    private Database db = Database.getDatabase();
    private ArrayList<Bill> bills = new ArrayList<>();

    public PrintBillController() {
        try {
            categories.addAll(db.getAllCategories());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex);
        }
    }

    public ArrayList<Category> getCategories() {
        return categories;
    }

    public ArrayList<Bill> getBills() throws Exception {
        return bills;
    }

    public ArrayList<Bill> getBills(Date from, Date since) throws Exception {
        bills.clear();
        bills.addAll(db.getBills(new java.sql.Date(from.getTime()),
                new java.sql.Date(since.getTime())));
        return bills;
    }

    public void updateList(Date from, Date since, ArrayList<Category> cat) throws Exception {
        bills.clear();
        bills.addAll(db.getBills(new java.sql.Date(from.getTime()),
                new java.sql.Date(since.getTime()), cat));
    }
}